<template>
  <van-popup v-model="show" position="bottom" :style="{ height: '100%' }">
    <div class="page">
      <van-nav-bar title="出库申请" left-arrow @click-left="$router.go(-1)"/>
      <van-form class="page-content" :disabled="btnLoading" @submit="submit">
        <van-field :rules="[ $check('请输入数字', 'number'), $check('请输入0-99', 'n99') ]" required label="机柜数"
          v-model.number="info.terminalNum" placeholder="请输入机柜数"/>
        <van-field :rules="[ $check('请输入数字', 'number'), $check('请输入0-99', 'n99') ]" required label="充电宝数"
          v-model.number="info.chargerNum" placeholder="请输入机柜数"/>
        <div style="margin: 1rem 16px 16px;">
          <van-button block type="info" :loading="btnLoading">提交</van-button>
        </div>
      </van-form>
    </div>
  </van-popup>
</template>

<script>
export default {
  data() {
    return {
      show: true,
      info: {
        terminalNum: 0,
        chargerNum: 0
      },
      btnLoading: false,
    };
  },
  methods: {
    submit() {
      let query = JSON.parse(JSON.stringify(this.info));
      if (query.equipmentNumber == 0 && query.chargerNumber) {
        this.$toast('请至少申请1个机柜或充电宝');
        return ;
      }
      this.btnLoading = true;
      this.$axios.post('/api/bjk/apply', query).then(res => {
        this.btnLoading = false;
        this.$emit('reloadList');
      }).catch(() => {
        this.btnLoading = false;
      });
    }
  },
  mounted() { 

  }
};
</script>

<style lang="less">
</style>
